package com.example.sunlight.interneteverything;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.widget.ListView;

import com.example.sunlight.interneteverything.Adapter.TrafficBaseAdapter;
import com.example.sunlight.interneteverything.View.TraffcRoteView;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created by SunLight on 2017/8/17.
 */

public class TrafficScheduling extends Activity {
    TraffcRoteView Zhang, Shui;
    ListView listView;
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 0x123:
                    Zhang.setNumber(new Random().nextInt(300) + "");
                    Shui.setNumber(new Random().nextInt(3) + "." + new Random().nextInt(100));
                    break;
            }
        }
    };
    List<String[]> list;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_trafficscheduling);
        FindView();
        textUpdate = new TextUpdate();
        textUpdate.start();
        list = new ArrayList<>();
        list.add(new String[]{"2017.07.25 8:25", "武黄立交往光谷方向有交通事故", "处理中"});
        list.add(new String[]{"2017.07.25 9:15", "友谊大道往二环方向有停车滞留", "请绕行"});
        list.add(new String[]{"2017.07.25 10:44", "京汉大道，循礼门往友谊路行车滞留", "请绕行"});
        list.add(new String[]{"2017.07.25 13:16", "二环线，珞狮路小学往马房山通道", "请绕行"});
        list.add(new String[]{"2017.07.25 15:22", "二环线，常码头往常青路行车滞留", "处理中"});
        TrafficBaseAdapter trafficBaseAdapter = new TrafficBaseAdapter(list, this);
        listView.setAdapter(trafficBaseAdapter);
    }

    TextUpdate textUpdate;

    public void FindView() {
        Zhang = (TraffcRoteView) findViewById(R.id.zhang);
        Shui = (TraffcRoteView) findViewById(R.id.shui);
        listView = (ListView) findViewById(R.id.list);
    }

    class TextUpdate extends Thread {
        @Override
        public void run() {
            while (true) {
                try {
                    Thread.sleep(5000);
                    handler.sendEmptyMessage(0x123);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
